//
//  AgreementViewController.m
//  SimpleDemo
//
//  Created by tw001 on 15/8/14.
//  Copyright (c) 2015年 wave. All rights reserved.
//

#import "AgreementViewController.h"

@interface AgreementViewController ()

@end

@implementation AgreementViewController

- (void)dealloc
{
    NSLog(@"协议释放");
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title=@"用户协议";
    
    UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64 - 50)];
    [self.view addSubview:webView];
    
    //底部bar条的颜色
    UIView *barView = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-50, self.view.frame.size.width, 50)];
    barView.backgroundColor = COLOR(37, 161, 85, 1);
    [self.view addSubview:barView];
    
    //已获知按钮的颜色
    UIButton *checkBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    checkBtn.frame = CGRectMake(self.view.frame.size.width/2.0-50, 10, 100, 30);
    checkBtn.backgroundColor = COLOR(37, 161, 85, 1);
    checkBtn.layer.cornerRadius = 3;
    [checkBtn setTitle:@"已获知" forState:UIControlStateNormal];
    [checkBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    checkBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [checkBtn addTarget:self action:@selector(backBtn:) forControlEvents:UIControlEventTouchUpInside];
    [webView.scrollView addSubview:checkBtn];
    [barView addSubview:checkBtn];
    //请求本地htm文件在webView中加载
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.25 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        
        NSString *path = [[NSBundle mainBundle] pathForResource:@"agreement" ofType:@"htm"];
        NSURL *url = [NSURL fileURLWithPath:path];
        NSURLRequest *request = [NSURLRequest requestWithURL:url] ;
        [webView loadRequest:request];
    });
}

- (void)backBtn:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

@end